<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
<script>
    let data = [{
        fileName: 'aaaaaaa.doc',
        url: 'http://www.baidu.com/aaaaaaa.doc',
        size: 123456789,
        a: 10,
        b: 15,
        c: 20
    }, {
        fileName: 'bbbbbbb.xls',
        url: 'http://www.baidu.com/bbbbbbb.xls',
        size: 6554412,
        a: 10,
        b: 15,
        c: 20
    }, {
        fileName: 'ccccccc.ppt',
        url: 'http://www.baidu.com/ccccccc.ppt',
        size: 85145531,
        a: 10,
        b: 15,
        c: 20
    }]

    let columns = {}

    Object.keys(data[0]).forEach(item => {
        Object.defineProperty(columns, item, { // 将item中的值设置为0
            value: 0,
            writable: true,
            enumerable: true,
            configurable: true
        })
    })

    console.log(columns)

    for (let item in columns) { //  a  b  c  fileName  size   url
        let total = data.reduce((total, row,index,obj) => { // 初始值，当前元素,索引，数组对象（后两个参数可选）
            return total + parseInt(row[item])
        }, 0)
        columns[item] = !isNaN(total) ? total : '--' // 不能省略，处理数据不为数字的情况
    }
    console.log(columns)
</script>
</body>

</html>
